/*
 * VennMaster/geometry/MathUtility.java
 * 
 * Created on 30.06.2004
 * 
 */
package visiopuce.ideogram.util;


/**
 * @author muellera
 */
public class MathUtility
{

	

	/**
	 * Restricts the given value <var>value</var> to the interval
	 * [lower,upper].
	 * @param value
	 * @param lower
	 * @param upper
	 * @return The restricted value.
	 */
	public static double restrict(double value, double lower, double upper)
	{
		if( lower > upper )
			throw new IllegalArgumentException("lower must be smaller than upper");
		if( value < lower )
		{
			return lower;
		}
		else
		{
			if( value > upper )
			{
				return upper;
			}
		}
		return value;
	}
	


	/**
	 * Restricts the given value <var>value</var> to the interval
	 * [lower,upper].
	 * @param value
	 * @param lower
	 * @param upper
	 * @return the restricted value
	 */
	public static int restrict(int value, int lower, int upper)
	{
		if( lower > upper )
			throw new IllegalArgumentException("lower must be smaller than upper");
		if( value < lower )
		{
			return lower;
		}
		else
		{
			if( value > upper )
			{
				return upper;
			}
		}
		return value;
	}
  


}
